home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / sswitchxp152.exe / source / SpeedswitchXP / TrayIconManager.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-14  |  7.7 KB  |  263 lines

  1. /*
  2.    SpeedswitchXP V1.5
  3.    Copyright(c) 2002-2006 Christian Diefer
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License version 2 as 
  7.    published by the Free Software Foundation.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19. #define _UNICODE
  20.  
  21. #include "stdafx.h"
  22. #include "TOptions.h"
  23. #include "AtlBase.h"
  24. #include "TrayIconManager.h"
  25. #include <winuser.h>
  26.  
  27. static unsigned char digits[25][8] = 
  28. {
  29.   // Ziffern 0-9 in 8x8:
  30.   { 0x3c,0x42,0x42,0x42,0x42,0x42,0x42,0x3c },
  31.   { 0x10,0x30,0x70,0x10,0x10,0x10,0x10,0x7c },
  32.   { 0x3c,0x42,0x02,0x04,0x08,0x10,0x20,0x7e },
  33.   { 0x3c,0x42,0x02,0x0c,0x02,0x02,0x42,0x3c },
  34.   { 0x08,0x18,0x28,0x48,0xfe,0x08,0x08,0x3e },
  35.   { 0x7e,0x40,0x40,0x7c,0x02,0x02,0x42,0x3c },
  36.   { 0x1c,0x20,0x40,0x7c,0x42,0x42,0x42,0x3c },
  37.   { 0x7c,0x44,0x08,0x08,0x10,0x10,0x20,0x20 },
  38.   { 0x3c,0x42,0x42,0x3c,0x42,0x42,0x42,0x3c },
  39.   { 0x3c,0x42,0x42,0x42,0x3e,0x02,0x04,0x38 },
  40.  
  41.   // Ziffern 0-9 in 5x8:
  42.   { 0x60,0x90,0x90,0x90,0x90,0x90,0x90,0x60 },
  43.   { 0x20,0x20,0x60,0x20,0x20,0x20,0x20,0x70 },
  44.   { 0x60,0x90,0x10,0x20,0x20,0x40,0x40,0xf0 },
  45.   { 0x60,0x90,0x10,0x20,0x10,0x10,0x90,0x60 },
  46.   { 0x20,0x60,0x60,0xa0,0xf0,0x20,0x20,0x70 },
  47.   { 0xf0,0x80,0x80,0xe0,0x10,0x10,0x90,0x60 },
  48.   { 0x70,0x80,0x80,0xe0,0x90,0x90,0x90,0x60 },
  49.   { 0xf0,0x90,0x10,0x10,0x20,0x20,0x20,0x20 },
  50.   { 0x60,0x90,0x90,0x60,0x90,0x90,0x90,0x60 },
  51.   { 0x60,0x90,0x90,0x90,0x70,0x10,0x20,0x60 },
  52.  
  53.   // 1 zusΣtzliches Zeichen fⁿr '-' in 8x8:
  54.   { 0x00,0x00,0x00,0x7e,0x7e,0x00,0x00,0x00 },
  55.  
  56.   // 4 zusΣtzliche Zeichen fⁿr 'Sl' und 'Hi' in 8x8:
  57.   { 0x3e,0x40,0x40,0x40,0x3c,0x02,0x02,0x7c },
  58.   { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x3c },
  59.   { 0x42,0x42,0x42,0x42,0x7e,0x42,0x42,0x42 },
  60.   { 0x00,0x00,0x10,0x00,0x10,0x10,0x10,0x38 }
  61. };
  62.  
  63. static int colorVal[16][3] = 
  64. {
  65.   {0, 0, 0},            // Black
  66.   {128, 0, 0},        // Dark Red
  67.   {0, 128, 0},        // Dark Green
  68.   {128, 128, 0},    // Dark Yellow
  69.   {0, 0, 128},        // Dark Blue
  70.   {128, 0, 128},    // Dark Magenta
  71.   {0, 128, 128},    // Dark Cyan    
  72.   {192, 192, 192},// Light Grey
  73.   {128, 128, 128},// Medium Grey
  74.   {255, 0, 0},        // Red
  75.   {0, 255, 0},        // Green
  76.   {255, 255, 0},    // Yellow
  77.   {0, 0, 255},      // Blue
  78.   {255, 0, 255},    // Magenta
  79.   {0, 255, 255},    // Cyan
  80.   {255, 255, 255}    // White
  81. };
  82.  
  83.  
  84. //---------------------------------------------------
  85. // fⁿllt die Bitmap fⁿr ein Icon
  86. //   upperStatus: true, wenn der obere Iconteil gefⁿllt werden soll
  87. //   upperValue: der im oberen Iconbereich anzuzeigende Wert
  88. //   lowerStatus: true, wenn der untere Iconteil gefⁿllt werden soll
  89. //   lowerValue: der im unteren Iconbereich anzuzeigende Wert
  90. //   iconType: 0=1.Systemicon, 1=2.Systemicon, 2=Lⁿftericon
  91. //---------------------------------------------------
  92. HICON TTrayIconManager::createIcon( bool upperStatus, int upperValue, bool lowerStatus, int lowerValue )
  93. {
  94.   DWORD dwWidth, dwHeight;
  95.   BITMAPINFO* bi;
  96.   HBITMAP hBitmap;
  97.   void *lpBits;
  98.   HICON hIcon = NULL;
  99.  
  100.   dwWidth  = 16;
  101.   dwHeight = 16;
  102.  
  103.   bi = (BITMAPINFO*)new char[ sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2]; 
  104.  
  105.   ZeroMemory( bi, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 );
  106.  
  107.   bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  108.   bi->bmiHeader.biWidth = dwWidth;
  109.   bi->bmiHeader.biHeight = dwHeight;
  110.   bi->bmiHeader.biPlanes = 1;
  111.   bi->bmiHeader.biBitCount = 1;
  112.   bi->bmiHeader.biCompression = BI_RGB;
  113.  
  114.   bi->bmiColors[0].rgbRed = colorVal[options.iconColor1][0];
  115.   bi->bmiColors[0].rgbGreen = colorVal[options.iconColor1][1];
  116.   bi->bmiColors[0].rgbBlue = colorVal[options.iconColor1][2];
  117.   bi->bmiColors[1].rgbRed = colorVal[options.iconColor2][0];
  118.   bi->bmiColors[1].rgbGreen = colorVal[options.iconColor2][1];
  119.   bi->bmiColors[1].rgbBlue = colorVal[options.iconColor2][2];
  120.   bi->bmiColors[0].rgbReserved = 0;
  121.   bi->bmiColors[1].rgbReserved = 0;
  122.  
  123.   HDC hdc = ::GetDC( NULL );
  124.  
  125.   hBitmap = CreateDIBSection( hdc, 
  126.                               bi, 
  127.                               DIB_RGB_COLORS,
  128.                               (void**)&lpBits, 
  129.                               NULL, 
  130.                               (DWORD)0 );
  131.  
  132.   BYTE* bitmap = (BYTE*)lpBits;
  133.  
  134.   createTempIcon( upperStatus?upperValue:lowerValue, (upperStatus&&lowerStatus)?1:0, bitmap );
  135.  
  136.   if( upperStatus && lowerStatus )
  137.     createTempIcon( lowerValue, 2, bitmap );
  138.  
  139.   // Create mask bitmap
  140.   BYTE andMask[128];
  141.  
  142.   for( int i=0; i<128; i++ )
  143.     andMask[i] = 0x00;
  144.  
  145.   if( options.iconTransparent )
  146.   {
  147.     int k = 15;
  148.  
  149.     for( int i=0; i<16; i++ )
  150.     {
  151.       for( int j=0; j<2; j++ )
  152.         andMask[k*2+j] = bitmap[i*4+j];
  153.       k--;
  154.     }
  155.   }
  156.  
  157.   HBITMAP hMonoBitmap = CreateBitmap( dwWidth, dwHeight, 1, 1, andMask );
  158.  
  159.   ICONINFO ii;
  160.   ii.fIcon = TRUE;
  161.   ii.xHotspot = 0;
  162.   ii.yHotspot = 0;
  163.   ii.hbmMask = hMonoBitmap;
  164.   ii.hbmColor = hBitmap;
  165.  
  166.   hIcon = CreateIconIndirect( &ii );
  167.  
  168.   ::ReleaseDC( glb_hWnd, hdc );
  169.   ::DeleteObject( hBitmap );
  170.   ::DeleteObject( hMonoBitmap );
  171.  
  172.   delete bi;
  173.  
  174.   return hIcon;
  175. }
  176.  
  177.  
  178. //---------------------------------------------------------------
  179. // Iconbitmap mit bestimmtem Wert fⁿllen
  180. //
  181. // temp: 0-200 = normale Temperatur oder Last (0-100)
  182. //       -3    = '--' anzeigen
  183. //       -4    = 'Sl' anzeigen
  184. //       -5    = 'Hi' anzeigen
  185. //---------------------------------------------------------------
  186. void TTrayIconManager::createTempIcon( int temp, int where, BYTE* and )
  187. {
  188.   int num0 = (temp/100)%10;   // erste Dezimalziffer
  189.   int num1 = (temp/10)%10;    // zweite Dezimalziffer
  190.   int num2 = temp%10;         // dritte Dezimalziffer
  191.   int j;
  192.   int lstart, lend, yscaling;
  193.  
  194.   if( temp == -3 )      // Spezialfall fⁿr 'inaktiv' ("--")
  195.   {
  196.     num0 = 0;
  197.     num1 = 20;
  198.     num2 = 20;
  199.   }
  200.   else if( temp == -4 )   // Zeichen fⁿr 'Sl' auswΣhlen
  201.   {
  202.     num0 = 0;
  203.     num1 = 21;
  204.     num2 = 22;
  205.   }
  206.   else if( temp == -5 )   // Zeichen fⁿr 'Hi' auswΣhlen
  207.   {
  208.     num0 = 0;
  209.     num1 = 23;
  210.     num2 = 24;
  211.   }
  212.  
  213.   if( where == 0 )        // nur ein Wert im Icon
  214.   {
  215.     lstart = 0;     // komplette Iconbitmap damit fⁿllen
  216.     lend = 15;
  217.     yscaling = 2;   // jede Ziffer auf 16 Zeilen erweitern
  218.   }
  219.   else if( where == 1 )   // obere HΣlfte des Icons fⁿllen
  220.   {
  221.     lstart = 8;     // nur obere HΣlfte der Bitmap fⁿllen
  222.     lend = 15;
  223.     yscaling = 1;   // keine Skalierung (8 Zeilen)
  224.   }
  225.   else if( where == 2 )   // untere HΣlfte des Icons fⁿllen
  226.   {
  227.     lstart = 0;     // nur untere HΣlfte der Bitmap fⁿllen
  228.     lend = 7;
  229.     yscaling = 1;   // keine Skalierung (8 Zeilen)
  230.   }
  231.  
  232.   if( num0 != 0 )   // zur Anzeige von Fahrenheitwerten
  233.   {
  234.     j=7;
  235.     for( int i=lstart; i<=lend; i+=yscaling )
  236.     {
  237.       for( int m=0; m<yscaling; m++ )   // eine Iconzeile pro Durchlauf
  238.       {
  239.         and[(i+m)*4] = 0xff ^ (digits[num0+10][j] | digits[num1+10][j]>>5);
  240.         and[(i+m)*4+1] = 0xff ^ (digits[num1+10][j]<<3 | digits[num2+10][j]>>2);
  241.       }
  242.  
  243.       j--;   // weiter im digits2-Array
  244.     }
  245.   }
  246.   else              // Standardwerte (Celsius)
  247.   {
  248.     j=7;
  249.  
  250.     for( int i=lstart; i<=lend; i+=yscaling )    // Iconregion fⁿllen
  251.     {
  252.       for( int m=0; m<yscaling; m++ )   // eine Iconzeile pro Durchlauf
  253.       {
  254.         and[(i+m)*4] = 0xff ^ digits[num1][j];
  255.         and[(i+m)*4+1] = 0xff ^ digits[num2][j];
  256.       }
  257.  
  258.       j--;   // weiter im digits-Array
  259.     }
  260.   }
  261. }
  262.  
  263.